#include "Util.h"

std::string amqp::bytes_to_string(amqp_bytes_t datas) {
    return std::string((const char*)datas.bytes, datas.len);
}

amqp_bytes_t amqp::string_to_bytes(const std::string& data) {
    return amqp_cstring_bytes(data.c_str());
}

amqp_bytes_t amqp::dump_to_bytes(const std::string& data) {
    return amqp_bytes_malloc_dup((amqp_cstring_bytes(data.c_str())));
}

void amqp::ReleaseBytes(amqp_bytes_t& field) {
    if (field.bytes != nullptr) { amqp_bytes_free(field); }
}

void amqp::CopyBytes(amqp_bytes_t& dest, const amqp_bytes_t& src) {
    ReleaseBytes(dest);
    dest = amqp_bytes_malloc_dup(src);
}

void amqp::SetBytes(amqp_bytes_t& dest, const std::string& value) {
    ReleaseBytes(dest);
    dest = amqp_bytes_malloc_dup(string_to_bytes(value));
}
